
#include "data_global.h"

/*********************************************************
   data_global.c :
       1. 全局的互斥锁定义
       2. 全局的条件变量定义
       3. 全局的id和key定义（用于进程间通信：System V消息队列、共享内存、信号量）
       4. 全局的消息队列发送函数定义
 *********************************************************/

pthread_mutex_t mutex_client_request,
    mutex_refresh,
    mutex_sqlite,
    mutex_transfer,
    mutex_sms,
    mutex_buzzer,
    mutex_led;

pthread_cond_t cond_client_request,
    cond_refresh,
    cond_sqlite,
    cond_transfer,
    cond_sms,
    cond_buzzer,
    cond_led;

int msgid;
int shmid;
int semid;

//msg_key
key_t key;
key_t shm_key;
key_t sem_key;

char recive_phone[12] = {0};
char center_phone[12] = {0};

// 安防监控项目所有的环境信息
struct env_info_client_addr sm_all_env_info;

//消息队列发送函数
int send_msg_queue(long type, unsigned char text)
{
    struct msg msgbuf;
    msgbuf.type = 1L;
    msgbuf.msgtype = type;
    msgbuf.text[0] = text;

    if (msgsnd(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), 0) == -1)
    {
        perror("fail to msgsnd type2");
        exit(1);
    }

    return 0;
}
